#pragma once

namespace gtl
{

namespace dui
{

static const char* jrect_class = 
"// class rect \n"
"function rect(x, y, width, height) { \
	if(typeof(x) == 'object' && typeof(x.x) == 'number' && typeof(x.y) == 'number' && \
	typeof(x.width) == 'number' && typeof(x.height) == 'number') \
	{ \
		this.x1 = x.x; \
		this.y1 = x.y; \
		this.x2 = x.x + x.width; \
		this.y2 = x.y + x.height; \
		return; \
	} \
	\
	this.x1 = isNaN(x) ? 0 : Number(x); \
	this.y1 = isNaN(y) ? 0 : Number(y); \
	this.x2 = this.x1 + (isNaN(width) ? 0 : isNaN(width)); \
	this.y2 = this.y1 + (isNaN(height) ? 0 : isNaN(height)); \
};"

"rect.prototype.toString = function() { return 'rect'; };"

"rect.prototype.__defineGetter__('left', function() { return this.x1; }); \
rect.prototype.__defineGetter__('top', function() { return this.y1; }); \
rect.prototype.__defineGetter__('right', function() { return this.x2; }); \
rect.prototype.__defineGetter__('bottom', function() { return this.y2; }); \
rect.prototype.__defineGetter__('x', function() { return this.x1; }); \
rect.prototype.__defineGetter__('y', function() { return this.y1; }); \
rect.prototype.__defineGetter__('width', function() { return this.x2 - this.x1; }); \
rect.prototype.__defineGetter__('height', function() { return this.y2 - this.y1; });"

"rect.prototype.__defineSetter__('left', function(val) { return this.x1 = (val); }); \
rect.prototype.__defineSetter__('top', function(val) { return this.y1 = Number(val); }); \
rect.prototype.__defineSetter__('right', function(val) { return this.x2 = Number(val); }); \
rect.prototype.__defineSetter__('bottom', function(val) { return this.y2 = Number(val); }); \
rect.prototype.__defineSetter__('x', function(val) { return this.x1 = Number(val); }); \
rect.prototype.__defineSetter__('y', function(val) { return this.y1 = Number(val); }); \
rect.prototype.__defineSetter__('width', function(val) { return this.x2 = this.x1 + Number(val); }); \
rect.prototype.__defineSetter__('height', function(val) { return this.y2 = this.y1 + Number(val); });"

"rect.prototype.null = function() { \
	return this.x1 == this.x2 && this.x1 == 0 && this.y1 == this.y2 && this.y1 == 0; \
};"

"rect.prototype.empty = function() { \
	return this.x1 == this.x2 || this.y1 == y2; \
};"

"rect.prototype.valid = function() { \
	return this.x1 < this.x2 && this.y1 < this.y2; \
};"

"rect.prototype.pt_in_rect = function(x, y) { \
	return this.x1 <= Number(x) && Number(x) <= this.x2 && this.y1 <= Number(y) && Number(y) <= this.y2; \
};"

"rect.prototype.hit_test = function(x, y) { \
	return pt_in_rect(x, y); \
};"

"rect.prototype.clear = function() { \
	this.x1 = 0; \
	this.y1 = 0; \
	this.x2 = 0; \
	this.y2 = 0; \
};"

"rect.prototype.move = function(x, y) { \
	this.right = this.width + Number(x); \
	this.bottom = this.height + Number(y); \
	this.left = Number(x); \
	this.top = Number(y); \
};"

"rect.prototype.offset = function(x, y) { \
	this.x1 += Number(x); \
	this.x2 += Number(x); \
	this.y1 += Number(y); \
	this.y2 += Number(y); \
};"

"rect.prototype.inflate = function(x, y) { \
	this.x1 -= Number(x); \
	this.x2 += Number(x); \
	this.y1 -= Number(y); \
	this.y2 += Number(y); \
};"

"rect.prototype.deflate = function(x, y) { \
	this.x1 += Number(x); \
	this.x2 -= Number(x); \
	this.y1 += Number(y); \
	this.y2 -= Number(y); \
};"

"rect.prototype.intersect = function(rc) { \
	if(typeof(rc) != 'object' || rc.toString() != 'rect') \
		return new rect(); \
	 \
	var r = new rect(this.x, this.x, this.width, this.height); \
	if(r.right > rc.right) \
		r.right = rc.right;  \
	if(r.bottom > rc.bottom) \
		r.bottom = rc.bottom; \
	if(r.left < rc.left) \
		r.left = rc.left; \
	if(r.top < rc.top) \
		r.top = rc.top; \
	 \
	return r; \
};"

"rect.prototype.combin = function(rc) { \
	if(typeof(rc) != 'object' || rc.toString() != 'rect') \
		return new rect(); \
	 \
	var r = new rect(this.x, this.x, this.width, this.height); \
	if(r.right < rc.right) \
		r.right = rc.right; \
	if(r.bottom < rc.bottom) \
		r.bottom = rc.bottom; \
	if(r.left > rc.left) \
		r.left = rc.left; \
	if(r.top > rc.top) \
		r.top = rc.top; \
	\
	return r; \
};"

;

} // end of namespace dui

} // end of namespace gtl